// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.   
// Jad home page: http://www.kpdus.com/jad.html   
// Decompiler options: packimports(3)    
   
package com.kingre.et.chart;   
   
import java.awt.*;   
import java.util.List;
import java.util.Map;

import javax.swing.JPanel;   
import org.jfree.chart.*;   
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;   
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;   
import org.jfree.chart.plot.PlotOrientation;   
import org.jfree.chart.renderer.category.BarRenderer;   
import org.jfree.chart.title.TextTitle;   
import org.jfree.data.category.CategoryDataset;   
import org.jfree.data.category.DefaultCategoryDataset;   
import org.jfree.ui.*;   
   
public class CylinderBarChart
{   
    static class CustomBarRenderer extends BarRenderer   
    {   
   
        public Paint getItemPaint(int i, int j)   
        {   
            return colors[j % colors.length];   
        }   
   
        private Paint colors[];   
   
        public CustomBarRenderer(Paint apaint[])   
        {   
            colors = apaint;   
        }   
    }   
   
    
    public static JFreeChart generateChart(String title, String xLabel,
            String yLabel, List<Map<String, String>> list){
        CategoryDataset dataset = createDataset(list);   
        JFreeChart chart = createChart(title, xLabel, yLabel, dataset);   
        return chart;
    }
   
    private static CategoryDataset createDataset(List<Map<String, String>> list)   
    {   
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for(Map<String, String> map : list){
            dataset.addValue(Double.parseDouble(map.get("value")), "S1", map.get("vd"));
        }
        return dataset;      
    }   
   
    private static JFreeChart createChart(String title, String xLabel,
            String yLabel, CategoryDataset dataset)   
    {   
        JFreeChart chart = ChartFactory.createBarChart(   
                title,                    // chart title   
                xLabel,                   // domain axis label   
                yLabel,                   // range axis label   
                dataset,                  // data   
                PlotOrientation.VERTICAL, // orientation   
                false,                     // include legend   
                true,                     // tooltips   
                false                     // urls   
            );   
        CategoryPlot categoryplot = (CategoryPlot)chart.getPlot();   
        
        Paint apaint[] = createPaint();   
        CustomBarRenderer custombarrenderer = new CustomBarRenderer(apaint);   
        custombarrenderer.setItemLabelPaint(Color.black);
        custombarrenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        custombarrenderer.setItemLabelFont(new Font("黑体",Font.PLAIN,14));
        custombarrenderer.setItemLabelPaint(Color.black);
        custombarrenderer.setItemLabelsVisible(true);
        ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);   
        custombarrenderer.setPositiveItemLabelPosition(itemlabelposition);  
        
        custombarrenderer.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));   
        categoryplot.setRenderer(custombarrenderer);   
        NumberAxis numberaxis = (NumberAxis)categoryplot.getRangeAxis();   
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());   
        numberaxis.setTickMarkPaint(Color.black);   
        
        CategoryAxis domainAxis = categoryplot.getDomainAxis();
        domainAxis.setLowerMargin(0.01);
        domainAxis.setUpperMargin(0.01);//设置距离图片右端距离此时为百分之10
        
        chart.getTitle().setFont(new Font("宋体", Font.PLAIN, 16));
        chart.setBackgroundPaint(Color.WHITE);
        /*------设置X轴坐标上的文字-----------*/
        domainAxis.setTickLabelFont(new Font("黑体", Font.PLAIN, 11));
        /*------设置X轴的标题文字------------*/
        domainAxis.setLabelFont(new Font("黑体", Font.PLAIN, 14));
        /*------设置Y轴坐标上的文字-----------*/
        numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
        /*------设置Y轴的标题文字------------*/
        numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 14));
        numberaxis.setTickUnit(new NumberTickUnit(10));
        numberaxis.setRange(0D, 90D);
        
        custombarrenderer.setMaximumBarWidth(0.06);
        categoryplot.setRenderer(custombarrenderer);
        
        return chart;   
    }   
   
    private static Paint[] createPaint()   
    {   
        Paint colors[] = new Paint[9];   
        colors[0] = new GradientPaint(0f, 0f, Color.white, 0f, 0f, Color.red);   
        colors[1] = new GradientPaint(0f, 0f, Color.white, 0f, 0f, Color.green);   
        colors[2] = new GradientPaint(0f, 0f, Color.white, 0f, 0f, Color.blue);   
        colors[3] = new GradientPaint(0f, 0f, Color.white, 0f, 0f, Color.orange);   
        colors[4] = new GradientPaint(0f, 0f, Color.white, 0f, 0f, Color.magenta);   
        colors[5] = new GradientPaint(0f, 0f, Color.white, 0f, 0f, Color.cyan);   
        colors[6] = new GradientPaint(0f, 0f, Color.white, 0f, 0f, Color.gray);   
        colors[7] = new GradientPaint(0f, 0f, Color.white, 0f, 0f, Color.pink);   
        colors[8] = new GradientPaint(0f, 0f, Color.white, 0f, 0f, Color.yellow);   
        return colors;   
    }   
   
}   